package com.cbn.ibcp.jishiting.rms.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.cbn.ibcp.common.annotation.DataSource;
import com.cbn.ibcp.common.enums.DataSourceType;
import com.cbn.ibcp.jishiting.rms.bo.ResourceStreamOrgBO;
import com.cbn.ibcp.jishiting.rms.domain.ResourceStreamOrg;
import com.cbn.ibcp.jishiting.rms.mapper.ResourceStreamOrgMapper;
import com.cbn.ibcp.jishiting.rms.service.IResourceStreamOrgService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Objects;


@Service
@RequiredArgsConstructor
public class ResourceStreamOrgServiceImpl implements IResourceStreamOrgService {

    private final ResourceStreamOrgMapper resourceStreamOrgMapper;


    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public ResourceStreamOrg selectListByStreamId(String tenantCode, String orgCode, Long streamId) {
        if (StrUtil.isBlank(orgCode) || streamId == null) {
            return null;
        }
        LambdaQueryWrapper<ResourceStreamOrg> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourceStreamOrg::getOrgCode, orgCode);
        queryWrapper.eq(ResourceStreamOrg::getStreamId, streamId);
        return resourceStreamOrgMapper.selectOne(queryWrapper);
    }

    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public List<ResourceStreamOrgBO> selectListByBO(String tenantCode, ResourceStreamOrgBO resourceStreamOrgBO) {
        if (resourceStreamOrgBO == null) {
            resourceStreamOrgBO = new ResourceStreamOrgBO();
        }
        return resourceStreamOrgMapper.selectListByBO(resourceStreamOrgBO);
    }

    @DataSource(DataSourceType.ibcp_rms)
    @Override
    public ResourceStreamOrg selectOneByVideoId(String tenantCode, String orgCode, Long videoId) {
        if (Objects.isNull(videoId)) {
            return null;
        }
        LambdaQueryWrapper<ResourceStreamOrg> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(ResourceStreamOrg::getResId, videoId);
        queryWrapper.eq(ResourceStreamOrg::getOrgCode, orgCode);
        return resourceStreamOrgMapper.selectOne(queryWrapper);
    }
}
